from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .models import User, UserAddress


@admin.register(User)
class UserAdmin(BaseUserAdmin):
    list_display = ['username', 'nickname', 'phone', 'is_vip', 'city', 'created_at']
    list_filter = ['is_vip', 'gender', 'created_at', 'is_staff', 'is_active']
    search_fields = ['username', 'nickname', 'phone', 'openid']
    ordering = ['-created_at']
    
    fieldsets = BaseUserAdmin.fieldsets + (
        ('微信信息', {
            'fields': ('openid', 'unionid', 'session_key')
        }),
        ('个人信息', {
            'fields': ('phone', 'avatar', 'nickname', 'gender', 'birthday', 'city')
        }),
        ('VIP信息', {
            'fields': ('is_vip', 'vip_expire_time')
        }),
    )
    
    readonly_fields = ['openid', 'unionid', 'session_key', 'created_at']


@admin.register(UserAddress)
class UserAddressAdmin(admin.ModelAdmin):
    list_display = ['user', 'name', 'phone', 'city', 'district', 'is_default', 'created_at']
    list_filter = ['is_default', 'province', 'city', 'created_at']
    search_fields = ['user__nickname', 'user__username', 'name', 'phone']
    ordering = ['-created_at']
    
    fieldsets = (
        ('收货人信息', {
            'fields': ('user', 'name', 'phone')
        }),
        ('地址信息', {
            'fields': ('province', 'city', 'district', 'detail', 'is_default')
        }),
    )